<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>老师端</title>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"
        integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

    <!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
        integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

    <link href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet">

    <style>
        html,
        body {
            margin: 0 auto;
            padding: 0;
            list-style: none;
            list-style-type: none;
        }

        * {
            box-sizing: border-box;
        }

        .img {
            width: 400px;
            margin: 0 auto;
            height: 300px;
        }

        .mt_20 {
            margin-top: 20px;
        }

        .contanier {
            margin: 0px auto;
        }


        .panel-body {
            padding: 0;
        }

        .panel-body .my_img {
            width: 100%;
            height: 100%;
        }
    </style>

</head>

<body>


    <div class="contanier">
        <div class="panel panel-default one">
            <div class="panel-heading">终端</div>
            <div class="panel-body">
                <img class="my_img" src="https://pic3.40017.cn/line/admin/2015/10/09/11/BZXCgG_640x360_00.png">
            </div>
            <div class="panel-footer">
                <button class="btn btn-success" id="btn_send">切换资源</button>
            </div>
        </div>
    </div>


    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>


    <!-- 首先引入 socket.io 客户端脚本-->
    <!-- <script src="/socket.io/socket.io.js"></script> -->
    <script src="https://cdn.bootcss.com/socket.io/2.1.0/socket.io.js"></script>
    <script type="text/javascript">
        var socket = io.connect(
        'http://47.103.36.143:8889'); //连接服务端，因为本机使用localhost 所以connect(url)中url可以不填或写 http://localhost
        // 监听 receiveMsg 事件，用来接收其他客户端推送的消息
        socket.on("clientReceiveChangeResource", function (data) {
            $(".my_img").attr('src', data.img_url);
        });

        var btn_send = document.getElementById("btn_send");
        btn_send.addEventListener("click", function () {

            //获取输入资源地址
            var sendMsg = [
                "https://pic5.40017.cn/01/001/89/43/rBLkBlrBzc2APIDbAAsoVkGvF6g090_640x360_00.jpg",
                "https://pic5.40017.cn/02/001/89/4a/rBLkCFrBzcmAYLGcAAqGMqqhNo4973_640x360_00.jpg",
                "https://pic5.40017.cn/01/000/89/43/rBLkBVrBzcuAZbjLAAm5Vq2luBY665_640x360_00.jpg",
                "https://pic5.40017.cn/01/000/37/43/rBLkBlo7ZDSAQGVXAANzeNCY3O0281_640x360_00.jpg",
                "https://pic5.40017.cn/02/000/37/36/rBLkCVo7ZDSAaJBdAAPig9hSN78654_640x360_00.jpg"
            ];

            var num = Math.floor(Math.random() * 4);

            img_url = sendMsg[num];

            var data = {
                client: "",
                resource_type: '1',
                img_url: img_url
            };
            //给服务端发送 sendMsg事件名的消息
            socket.emit("changeResource", data);
        });
    </script>

</body>

</html>